<?php 
/*
 module:		小程序设置
 create_time:	2022-03-07 19:45:21
 author:	陕西格创
 contact:		
*/

namespace app\api\controller;

use app\api\service\SysSiteService;
use app\api\model\SysSite as SysSiteModel;
use app\backend\model\Config;
use app\backend\model\ZhCurrencySetu;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\Log;

class SysSite extends Common {


	/**
	* @api {get} /SysSite/index 01、首页数据列表
	* @apiGroup SysSite
	* @apiVersion 1.0.0
	* @apiDescription  首页数据列表
	* @apiParam (输入参数：) {int}     		[limit] 每页数据条数（默认20）
	* @apiParam (输入参数：) {int}     		[page] 当前页码

	* @apiParam (失败返回参数：) {object}     	array 返回结果集
	* @apiParam (失败返回参数：) {string}     	array.status 返回错误码 201
	* @apiParam (失败返回参数：) {string}     	array.msg 返回错误消息
	* @apiParam (成功返回参数：) {string}     	array 返回结果集
	* @apiParam (成功返回参数：) {string}     	array.status 返回错误码 200
	* @apiParam (成功返回参数：) {string}     	array.data 返回数据
	* @apiParam (成功返回参数：) {string}     	array.data.list 返回数据列表
	* @apiParam (成功返回参数：) {string}     	array.data.count 返回数据总数
	* @apiSuccessExample {json} 01 成功示例
	* {"status":"200","data":""}
	* @apiErrorExample {json} 02 失败示例
	* {"status":" 201","msg":"查询失败"}
	*/
	function index(){
        $wxapp_id = $this->request->get('wxapp_id');
        if(!$wxapp_id){
            return $this->ajaxReturn($this->errorCode,'缺少平台参数');
        }
        $wxSetting = SysSiteModel::where('wxapp_id',$wxapp_id)->find();
        if(!$wxSetting){
            return $this->ajaxReturn($this->errorCode,'平台参数未配置');
        }
		$limit  = $this->request->get('limit', 1, 'intval');
		$page   = $this->request->get('page', 1, 'intval');

		$where = [
		    'wxapp_id'=>$wxapp_id
        ];
		$field = 'zs_agreement,yxzy,dzqy,xzcyl,wxapp_id,about_us,proportion,agreement,user_agreement,hn_agreement,currency_agreement,superior_take_prop,matchmaker_take_prop,platform_take_prop,no_vip_frequency,min_withdrawal';
		$orderby = 'id desc';

		$res = SysSiteService::indexList(formatWhere($where),$field,$orderby,$limit,$page);
		
		return $this->ajaxReturn($this->successCode,'返回成功',htmlOutList($res));
	}

	//获取红心页面路径
    function get_currentsetu(){
        $wxapp_id = $this->request->get('wxapp_id');
        if(!$wxapp_id){
            return $this->ajaxReturn($this->errorCode,'缺少平台参数');
        }
        $wxSetting = SysSiteModel::where('wxapp_id',$wxapp_id)->find();
        if(!$wxSetting){
            return $this->ajaxReturn($this->errorCode,'平台参数未配置');
        }
        $res=ZhCurrencySetu::find(1);
        return $this->ajaxReturn($this->successCode,'返回成功',$res);
    }
    //获取审核状态
    function get_audit(){
        $res = Config::where([
            "name"=>"audit_statu"
        ])->find();
        return $this->ajaxReturn($this->successCode,'返回成功',$res);
    }
    //获取招商付费
    function get_zs_agreement(){
        $wxapp_id = $this->request->get('wxapp_id');
        if(!$wxapp_id){
            return $this->ajaxReturn($this->errorCode,'缺少平台参数');
        }
        $wxSetting = SysSiteModel::where('wxapp_id',$wxapp_id)->field(["zs_agreement"])->find();
        if(!$wxSetting){
            return $this->ajaxReturn($this->errorCode,'平台参数未配置');
        }
        return $this->ajaxReturn($this->successCode,'返回成功',htmlspecialchars_decode($wxSetting["zs_agreement"]));
    }
      //营销资源
    function get_yxzy(){
        $wxapp_id = $this->request->get('wxapp_id');
        if(!$wxapp_id){
            return $this->ajaxReturn($this->errorCode,'缺少平台参数');
        }
        $wxSetting = SysSiteModel::where('wxapp_id',$wxapp_id)->field(["yxzy"])->find();
        if(!$wxSetting){
            return $this->ajaxReturn($this->errorCode,'平台参数未配置');
        }
        return $this->ajaxReturn($this->successCode,'返回成功',htmlspecialchars_decode($wxSetting["yxzy"]));
    }
    //电子签约
    function get_dzqy(){
        $wxapp_id = $this->request->get('wxapp_id');
        if(!$wxapp_id){
            return $this->ajaxReturn($this->errorCode,'缺少平台参数');
        }
        $wxSetting = SysSiteModel::where('wxapp_id',$wxapp_id)->field(["dzqy"])->find();
        if(!$wxSetting){
            return $this->ajaxReturn($this->errorCode,'平台参数未配置');
        }
        return $this->ajaxReturn($this->successCode,'返回成功',htmlspecialchars_decode($wxSetting["dzqy"]));
    }
    //西子产业链
    function get_xzcyl(){
        $wxapp_id = $this->request->get('wxapp_id');
        if(!$wxapp_id){
            return $this->ajaxReturn($this->errorCode,'缺少平台参数');
        }
        $wxSetting = SysSiteModel::where('wxapp_id',$wxapp_id)->field(["xzcyl"])->find();
        if(!$wxSetting){
            return $this->ajaxReturn($this->errorCode,'平台参数未配置');
        }
        return $this->ajaxReturn($this->successCode,'返回成功',htmlspecialchars_decode($wxSetting["xzcyl"]));
    }
}

